package com.yidianyanglao.userData.mapper;

import com.yidianyanglao.user.bean.UserBean;
import com.yidianyanglao.userData.bean.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by lf on 2016/11/03.
 */
@Repository
public interface UserDataMapper {

    /**
     * 通过ID获取系列对象
     * @param seriesId
     * @return
     */
    @Select("SELECT * FROM yl_series WHERE id = #{seriesId}")
    SeriesBean getSeriesById(String seriesId);

    /**
     * 通过用户ID、系列ID获取幸运树
     * @param userId
     * @param seriesId
     * @return
     */
    @Select("SELECT * FROM yl_luckytree WHERE user_id = #{userId} AND series_id = #{seriesId} AND usertype=0")
    LuckyTreeBean getTreeBySeriesId(@Param("userId") int userId,  @Param("seriesId")  String seriesId);

    /**
     * 通过用户ID、系列ID获取幸运树明细
     * @param userId
     * @param seriesId
     * @return
     */
    @Select("SELECT * FROM yl_tree_details WHERE user_id = #{userId} AND series_id = #{seriesId} AND usertype=0 order by createdate desc limit #{begin},10")
    List<TreeDetailsBean> getTreeDetailBySeriesId(@Param("begin") int begin, @Param("userId") int userId,  @Param("seriesId")  String seriesId);

    /**
     * 通过用户ID获取推荐列表
     * @param begin
     * @param userId
     * @return
     */
    @Select("SELECT * FROM yl_recommend_record WHERE fromuser_id = #{userId} order by createdate desc limit #{begin},10")
    List<RecommendRecordBean> getMyRecommendList(@Param("begin") int begin, @Param("userId") int userId);

    /**
     * 获取我的消费记录
     * @param map
     * @return
     */
    @Select("SELECT * FROM yl_order WHERE DATE_SUB(CURDATE(), INTERVAL #{days} DAY) <= DATE(createdate) and consumption_id=#{userId} AND series_id=#{seriesId} order by createdate desc limit #{begin},10")
    List<OrderBean> getMyOrderList(Map map);

    /**
     * 通过ID获取店铺
     * @param shopId
     * @return
     */
    @Select("SELECT * FROM yl_shop WHERE id = #{shopId}")
    ShopBean getShopById(int shopId);

    /**
     * 获取我的种子明细
     * @param begin
     * @param userId
     * @param name
     * @return
     */
    @Select("SELECT * FROM yl_seed_details WHERE user_id = #{userId} AND name like #{name} order by createdate desc limit #{begin},10")
    List<SeedDetailsBean> getMySeedDetails(@Param("begin") int begin, @Param("userId") int userId, @Param("name") String name);

    /**
     * 通过ID获取user
     * @param id
     * @return
     */
    @Select("SELECT * from yl_user where id=#{id}")
    UserBean getUserById(int id);

    /**
     * 查询当前用户的转赠数据
     * @param id
     * @return
     */
    @Select("SELECT s.*,u.headpic as obtainpeopleHeadImg FROM yl_seed_details s,yl_user u where s.obtainpeople_id = u.id AND `name` = '已转赠' AND user_id = #{id}  ORDER BY createdate DESC limit #{begin},10")
    List<SeedDetailsBean> getTurnSeedFetail(@Param("id")int id,@Param("begin")int begin);

}
